/*
 * Created by SharpDevelop.
 * User: daniel
 * Date: 12/25/2006
 * Time: 9:55 PM
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;

namespace MonoDoku
{
	/// <summary>
	/// Description of PossibilitySet.
	/// </summary>
	public class PossibilitySet
	{
		bool[] poss;
		
		public PossibilitySet(int size)
		{
			poss = new bool[size];
			for(int i = 0; i < poss.Length; i++){
				poss[i] = true;
			}
			
		}
		
		public void remove_possibility( int possibility ){
			poss[ possibility - 1 ] = false;
		}
		
		public bool is_single( ){
			bool found_one = false;
			for( int i = 0; i < poss.Length; i++ ){
				if( poss[i] == true ){
					if( found_one == true ){
						return false;
					} else {
						found_one = true;
					}
				}
			}
			return found_one;
		}
		
		public int get_single( ){
			for( int i = 0; i < poss.Length; i++ ){
				if( poss[i] == true ){
					return i + 1;
				}
			}
			//Shouldn't get here.
			return int.MinValue;
		}
		
		public bool has_none(){
			for(int i = 0; i < poss.Length; i++ ){
				if( poss[i] == true ) return false;
			}
			return true;
		}
		
		public int[] all_possibilities(){
			int count = 0;
			for( int i = 0; i < poss.Length; i++){
				if( poss[i] ) count++;
			}
			
			int[] toReturn = new int[ count ];
			int index = 0;
			
			for( int i = 0; i < poss.Length; i++){
				if( poss[i] ) {
					toReturn[ index ] = i + 1;
					index++;
				}
			}
			return toReturn;
		}
		
		
	}
}
